<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文字少时居中，多时居左</title>
</head>
<body>
    <style>
        div{
            color: #fff;
            width: 120px;
            padding: 10px;
            margin: 10px;
            background-color: #07b39b;
            text-align: center;

        }
        span{
            display: inline-block;
            text-align: left;
            background-color: #5e3700;
        }
    </style>
    <div>
        <span>短文字</span>
    </div>

    <div>
        <span>很长一段文字就会换行了</span>
    </div>
</body>
</html>